package com.whitedust.top70;

import java.util.Objects;
import java.util.Stack;

/**
 *
 * @author A
 * @since 2025/11/11 12:55
 */

public class Top62 {
    public static class MinStack {
        Stack<Integer> stack = new Stack<>();
        Stack<Integer> minValueStack = new Stack<>();

        public MinStack() {

        }

        public void push(int val) {
            stack.push(val);
            if (!minValueStack.isEmpty()) {
                if (minValueStack.peek() >= val) {
                    minValueStack.push(val);
                }
            } else {
                minValueStack.push(val);
            }
        }

        public void pop() {
            int pop = stack.pop();
            if (pop == minValueStack.peek()){
                minValueStack.pop();
            }

        }

        public int top() {
            return stack.peek();
        }

        public int getMin() {
            return minValueStack.peek();
        }
    }
}
